X-Git-Url: https://git.r.bdr.sh/rbdr/super-polarity/blobdiff_plain/8534e46e400268c5ceffb3b14f02cef39eedae8f..3de51c6f55d304f038df1b77c8ab346e2a187fe1:/Super%20Polarity/Widget.cs diff --git a/Super Polarity/Widget.cs b/Super Polarity/Widget.cs new file mode 100644 index 0000000..ea92cfd --- /dev/null +++ b/Super Polarity/Widget.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace SuperPolarity +{ + class Widget + { + public List Children; + public Dictionary>> Listeners; + + public Vector2 Position; + public SuperPolarity Game; + + protected bool Active; + + public Widget(SuperPolarity game, Vector2 position) + { + Game = game; + Position = position; + Active = false; + Children = new List(); + Listeners = new Dictionary>>(); + } + + public void Activate() + { + Active = true; + } + + public void Deactivate() + { + Active = false; + } + + public virtual void AppendChild(Widget widget) + { + Children.Add(widget); + } + + public virtual void Bind(string eventName, Action eventListener) + { + List> newListenerList; + List> listenerList; + bool foundListeners; + + if (!Listeners.ContainsKey(eventName)) + { + newListenerList = new List>(); + Listeners.Add(eventName, newListenerList); + } + + foundListeners = Listeners.TryGetValue(eventName, out listenerList); + + listenerList.Add(eventListener); + } + + public virtual void Unbind(string eventName, Action eventListener) + { + // NOT YET IMPLEMENTED; + } + + public virtual void Dispatch(string eventName, float value) + { + List> listenerList; + bool foundListeners; + + foundListeners = Listeners.TryGetValue(eventName, out listenerList); + + if (!foundListeners) + { + return; + } + + foreach (Action method in listenerList) + { + method(value); + } + } + + public virtual void Update(GameTime gameTime) + { + } + + public virtual void Draw(SpriteBatch spriteBatch) + { + } + } +}